﻿using System;
using Microsoft.WindowsAzure.StorageClient;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class contains an event of a group.
    /// 
    /// RowKey = ID of the event
    /// PartitionKey = ID of the group which has created the event
    /// </summary>
    public class Event : BasicDataModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Event"/> class.
        /// </summary>
        public Event()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Event"/> class.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="date">The date.</param>
        /// <param name="place">The place.</param>
        /// <param name="capacity">The capacity.</param>
        public Event(string group,string name, string description, DateTime date,string place, int capacity)
        {
            RowKey = Guid.NewGuid().ToString();
            PartitionKey = group;
            Description = description;
            Name = name;
            Date = date;
            Capacity = capacity;
            Place = place;
        }

        /// <summary>
        /// Gets or sets the group.
        /// </summary>
        /// <value>The group.</value>
        public string Group
        {
            get
            {
                return PartitionKey;
            }
            set
            {
                PartitionKey = value;
            }
        }
        /// <summary>
        /// Nombre del evento.
        /// </summary>
        [Required(ErrorMessage = "Debe introducir un nombre del evento.")]
        [DisplayName("Nombre")]
        public string Name { get; set; }
        /// <summary>
        /// Gets or sets the date of the event.
        /// </summary>
        /// <value>The event's date.</value>
        [Required(ErrorMessage = "Debe introducir una fecha.")]
        [DisplayName("Fecha")]
        public DateTime Date { get; set; }
        /// <summary>
        /// Gets or sets the description of the event.
        /// </summary>
        /// <value>The event's description.</value>
        [Required(ErrorMessage = "Debe introducir una descripcion del evento.")]
        [DisplayName("Descripción")]
        public string Description { get; set; }
        /// <summary>
        /// Gets or sets the capacity of the event.
        /// </summary>
        /// <value>The event's capacity.</value>
        [Required(ErrorMessage = "Debe introducir la capacidad del evento.")]
        [DisplayName("Capacidad")]
        public int Capacity{ get; set;}
        /// <summary>
        /// Gets or sets the place of the event.
        /// </summary>
        [Required(ErrorMessage = "Debe introducir el lugar del evento.")]
        [DisplayName("Lugar")]
        public string Place { get; set; }
        /// <summary>
        /// Gets the short name of the event.
        /// </summary>
        /// <returns>The short name of the event.</returns>
        public String GetShortName()
        {
            if (Name.Length <= 58)
            {
                return Name;
            }
            else
            {
                return String.Format("{0}...", Name.Substring(0, 55));
            }
        }
    }
}
